using System;

namespace TimeMachine.Engine.Vcs
{
	public class CommitInfo
	{
		public CommitInfo(string author, string message, int revision, DateTime date)
		{
			Author = author;
			Message = message;
			Revision = revision;
			Date = date;
		}

		public CommitInfo(CommitInfo commitInfo)
			: this(commitInfo.Author, commitInfo.Message, commitInfo.Revision, commitInfo.Date)
		{
		}

		public string Author { get; private set; }
		public string Message { get; private set; }
		public int Revision { get; private set; }
		public DateTime Date { get; private set; }

		public bool Equals(CommitInfo other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return Equals(other.Author, Author) && Equals(other.Message, Message) && other.Revision == Revision &&
			       other.Date.Equals(Date);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != typeof (CommitInfo)) return false;
			return Equals((CommitInfo) obj);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				int result = (Author != null ? Author.GetHashCode() : 0);
				result = (result*397) ^ (Message != null ? Message.GetHashCode() : 0);
				result = (result*397) ^ Revision;
				result = (result*397) ^ Date.GetHashCode();
				return result;
			}
		}

		public override string ToString()
		{
			return string.Format(
				"{2} {3} {0} {1}",
				Author, Message, Revision, Date);
		}
	}
}